package com.cjm.one.controller.coupon;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cjm.one.common.result.Result;
import com.cjm.one.model.coupon.dto.OrderCalculateDTO;
import com.cjm.one.model.coupon.vo.CouponInfoVo;
import com.cjm.one.model.coupon.vo.GoodsDiscountVO;
import com.cjm.one.service.CouponInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@Tag(name = "优惠卷", description = "优惠卷")
@RequestMapping("/api/coupon/info")
public class CouponInfoController {

    @Resource
    private CouponInfoService couponInfoService;
    @GetMapping("/list")
    @Operation(summary = "查询所有优惠券信息列表并判断是否被当前用户领取过")
    public Result<Page<CouponInfoVo>> getList(@RequestParam Long current,
                                              @RequestParam Long size ,
                                              @RequestParam(name = "rangeType", required = false)Integer rangeType) {
        return couponInfoService.getList(current, size, rangeType) ;
    }

    @PostMapping("/calculate")
    @Operation(summary = "计算最优折扣")
    public Result<List<GoodsDiscountVO>> calculateBestDiscount(
            @RequestBody OrderCalculateDTO calculateDTO){
        return couponInfoService.calculateBestDiscount(calculateDTO);
    }

}
